let router = require('express').Router();
let {execute} = require('../db/utils');
// /api/data?type=nodejs
router.get('/data', async function (req, res) {
  // 分页
  let {type, page = 1, pageCount = 100} = req.query; //

  if (page < 1 || pageCount < 0) {
    res.statusCode = 422;
    // 常见的错误状态 : 401:数据  400:请求方式出错 404 403:资源 422:参数出错 ...
    // 500+:服务器 504:代理
    res.json({
      code: -1,
      msg: '参数出错'
    });
    return
  }

  let sql = `select * from inter where type="${type}" limit ${(page - 1) * pageCount},${pageCount}`;
  let result = await execute(sql);
  res.json({
    code: 1,
    result
  });
});


module.exports = router;
